const stringifyRequest = require("loader-utils").stringifyRequest;

module.exports.pitch = function(remainingRequest) {
	return `
	import await { getString as _getString, memory } from ${stringifyRequest(
		this,
		`${this.resourcePath}.wat!=!${remainingRequest}`
	)};

	export function getString() {
		const strBuf = new Uint8Array(memory.buffer, _getString());
		const idx = strBuf.indexOf(0);
		const strBuf2 = strBuf.slice(0, idx);
		const str = Buffer.from(strBuf2).toString("utf-8");
		return str;
	};
	`;
};
